<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .color{
            color: red;
        }
    </style>
</head>
<body>
    <!-- 作用域插槽 可以操作子组件中的数据的展示效果等 -->
    <div id="app">
        <my-cpn>
            <template slot-scope="slotData">
                <div v-if="slotData.item.id === 1" class="color">
                    {{ slotData.item.name }}
                </div>
                <div v-else>
                    {{ slotData.item.name }}
                </div>
            </template>
        </my-cpn>
    </div>
    <script src="../js/vue.js"></script>
    <template id="myCpn">
        <div>
            <ul>
                <li v-for="item in list" :key="item.id">
                    <slot :item="item">
                        {{ item.name }}
                    </slot>
                </li>
            </ul>
        </div>
    </template>
    <script>
        const app = new Vue({
            el:'#app',
            data(){
                return {

                }
            },
            components:{
                'my-cpn':{
                    template:'#myCpn',
                    data(){
                        return {
                            list:[
                                {
                                    id:1,
                                    name:'我是数据1'
                                },
                                {
                                    id:2,
                                    name:'我是数据2'
                                },
                                {
                                    id:3,
                                    name:'我是数据3'
                                }
                            ]
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>